<!doctype html>
<html class="no-js fixed-layout">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>投票系统后台管理</title>
  <meta name="description" content="这是一个 index 页面">
  <meta name="keywords" content="index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="../../../assets/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="../../../assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="../../../assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="../../../assets/css/admin.css">
	 <script type="text/javascript"   src="../../../js/jquery-1.11.3.min.js"></script>
	 <script type="text/javascript"  src="../../../js/cookie_util.js"></script>
	<script type="text/javascript">
		function delete_activity(e){
			var activity_id = $(e).parent().parent().parent().parent().children("td").eq(0).html();
		 	$.ajax({
    			url:"http://localhost:8080/ciic-vote/activity/deleteActivity.do",
    			type:"post",
    			data:{"activityId":activity_id},
    			dataType:"json",
    			success:function(result){
    				if(result.status == 0){
						alert("删除活动成功");
						window.location.href="findAll.html";
    				}
    			}
    		});			
		}
		function modify_count(e){
			var activity_id = $(e).parent().parent().parent().parent().children("td").eq(0).html();
			var activity_title = $(e).parent().parent().parent().parent().children("td").eq(1).html();
			addCookie("activity_id",activity_id,2);
			addCookie("activity_title",activity_title,2);
			window.location.href="modify_count.html";
		}
		function modify_activity(e){
			var activity_id = $(e).parent().parent().parent().parent().children("td").eq(0).html();
			var activity_title = $(e).parent().parent().parent().parent().children("td").eq(1).html();
			addCookie("activity_id",activity_id,2);
			addCookie("activity_title",activity_title,2);
			window.location.href="modify_activity.html";
		}
	 	$(function(){
		 	$.ajax({
    			url:"http://localhost:8080/ciic-vote/activity/findAll.do",
    			type:"post",
    			dataType:"json",
    			success:function(result){
    				if(result.status == 0){
    					var list = result.data;
    					for(var i=0; i<list.length; i++){
    						var id = list[i].id;
    						var title = list[i].title;
    						var create_at =list[i].create_at;
    						create_at = getSmpFormatDateByLong(create_at,false);
    						var begin_at = list[i].begin_at;
    						begin_at = getSmpFormatDateByLong(begin_at,false);
    						var end_at = list[i].end_at;
    						end_at = getSmpFormatDateByLong(end_at,false);
    						var state_str = null;
    						var state = list[i].state;
    						if(state == 0){
    							state_str = "活动";
    						}
    						if(state == 1){
    							state_str = "不活动";
    						}
    						var creatorId= list[i].creator;
       						var creator = null;
    						$.ajax({
    			    			url:"http://localhost:8080/ciic-vote/user/findById.do",
    			    			type:"post",
    			    			dataType:"json",
    			    			async:false, 
    			    			data:{"id":creatorId},
    			    			success:function(result3){
    			    				creator = result3.username;
    			    			}
    			    		});
    						$.ajax({
    			    			url:"http://localhost:8080/ciic-vote/vote/findByActivityId.do",
    			    			type:"post",
    			    			dataType:"json",
    			    			async:false, 
    			    			data:{"activityId":id},
    			    			success:function(result2){
    			    				if(result2.status == 0){
    			    					var list2 = result2.data;
    			    					/* vote_1 = list2[0].title;
    			    					vote_2 = list2[1].title;
    			    					vote_1_count = list2[0].count;
    			    					vote_2_count = list2[1].count; */
    			    					var votes_count = list2.length;
    			    					if(votes_count >= 1){
    			    						var votes_0 = list2[0].title;
        			    					var votes_0_count = list2[0].count;
	    			    					var li = '<tr><td rowspan="';
	    			    					li += votes_count;
	    			    					li += '" align="center" style="vertical-align:middle;">';
	    		        					li += id;
	    		        					li += '</td><td rowspan="';
	    		        					li += votes_count;
	    		        					li += '" align="center" style="vertical-align:middle;">';
	    		        					li += title;
	    		        					li += '</td><td>';
	    		        					li += votes_0;
	    		        					li += '</td><td>';
	    		        					li += votes_0_count;
	    		        					li += '</td><td rowspan="';
	    		        					li += votes_count;
	    		        					li += '" align="center" style="vertical-align:middle;">';
	    		        					li += create_at;
	    		        					li += '</td><td rowspan="';
	    		        					li += votes_count;
	    		        					li += '" align="center" style="vertical-align:middle;">';
	    		        					li += begin_at;
	    		        					li += '</td><td rowspan="';
	    		        					li += votes_count;
	    		        					li += '" align="center" style="vertical-align:middle;">';
	    		        					li += end_at;
	    		        					li += '</td><td rowspan="';
	    		        					li += votes_count;
	    		        					li += '" align="center" style="vertical-align:middle;">';
	    		        					li += state_str;
	    		        					li += '</td><td rowspan="';
	    		        					li += votes_count;
	    		        					li += '" align="center" style="vertical-align:middle;">';
	    		        					li += creator;
	    		        					li += '</td><td rowspan="';
	    		        					li += votes_count;
	    		        					li += '" align="center" style="vertical-align:middle;">';
	    		        	                li +=  '<div class="am-btn-toolbar">';
	    		        	                li +=    '<div class="am-btn-group am-btn-group-xs manage_btns">';
	    		        	                li +=      '<button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="modify_count(this)"><span class="am-icon-pencil-square-o"></span> 修改票数</button>';
	    		        	                li +=      '<button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="modify_activity(this)"><span class="am-icon-pencil-square-o"></span> 修改活动</button>';
	    		        	                li +=      '<button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="delete_activity(this)"><span class="am-icon-trash-o"></span> 删除</button>';
	    		        	                li +=    '</div>';
	    		        	                li +=  '</div>';
	    		        					li += '</td>';
	    		        					li += '</tr>';
	    		        					li = $(li);
	    		    						$("#user_list").append(li);
	    			    					for(var i=1; i<votes_count; i++){
	    			    						var votes_i = list2[i].title;
	        			    					var votes_i_count = list2[i].count;
	    			    						var li2 = '<tr><td>';
	    			        					li2 += votes_i;
	    			        					li2 += '</td><td>';
	    			        					li2 += votes_i_count;
	    			        					li2 += '</td>';
	    			        					li2 += '</tr>';
	    			        					li2 = $(li2);
	    			    						$("#user_list").append(li2);	
	    			    					}
    			    					}
    			    				}
    			    			}
    		    			});
    						
        					
    					}
    				}
    			}
    		});
    		
	 	});
	 </script>
	 <style>
	 	td {
	 		border:1px dashed #eee;
	 	}
	 	.manage_btns {
	 		padding-left:35px;
	 	}
	 </style>
</head>
<body>

<header class="am-topbar am-topbar-inverse admin-header">
  <div class="am-topbar-brand">
    <strong>投票系统</strong> <small>后台管理</small>
  </div>

  <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

  <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

    <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
      <li class="am-dropdown" data-am-dropdown>
        <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
          <span class="am-icon-users"></span> <span id="userName"></span> <span class="am-icon-caret-down"></span>
        </a>
        <ul class="am-dropdown-content">
          <li><a href="javascript:void(0)" onclick="exit();"><span class="am-icon-power-off"></span> 退出</a></li>
        </ul>
      </li>
      <li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen"><span class="am-icon-arrows-alt"></span> <span class="admin-fullText">开启全屏</span></a></li>
    </ul>
  </div>
</header>

<div class="am-cf admin-main">
  <!-- sidebar start -->
  <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
    <div class="am-offcanvas-bar admin-offcanvas-bar">
      <ul class="am-list admin-sidebar-list">
        <li><a href="../../user/super/success.html"><span class="am-icon-home"></span> 首页</a></li>
        <li class="admin-parent">
          <a class="am-cf" data-am-collapse="{target: '#collapse-nav'}"><span class="am-icon-file"></span> 用户管理 <span class="am-icon-angle-right am-fr am-margin-right"></span></a>
          <ul class="am-list am-collapse admin-sidebar-sub am-in" id="collapse-nav">
            <li><a href="../../user/super/create_user.html" class="am-cf"><span class="am-icon-check"></span> 创建用户<span class="am-icon-star am-fr am-margin-right admin-icon-yellow"></span></a></li>
            <li><a href="../../user/super/findAll.html"><span class="am-icon-puzzle-piece"></span> 查看用户</a></li>
          </ul>
        </li>
        <li class="admin-parent">
          <a class="am-cf" data-am-collapse="{target: '#collapse-nav2'}"><span class="am-icon-file"></span> 活动管理 <span class="am-icon-angle-right am-fr am-margin-right"></span></a>
          <ul class="am-list am-collapse admin-sidebar-sub am-in" id="collapse-nav2">
            <li><a href="create_activity.html" class="am-cf"><span class="am-icon-check"></span> 创建活动<span class="am-icon-star am-fr am-margin-right admin-icon-yellow"></span></a></li>
            <li><a href="findAll.html"><span class="am-icon-puzzle-piece"></span> 查看活动</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
  <!-- sidebar end -->

  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">活动管理</strong> / <small>活动列表</small></div>
      </div>
      
      <div class="am-g">
        <div class="am-u-sm-12">
          <table class="am-table am-table-bd  admin-content-table" style="border:1px solid black;">
           
            <thead>
            <tr>
              <th>ID</th><th>活动名称</th><th>投票项</th><th>票数</th><th>创建时间</th><th>开始时间</th><th>结束时间</th><th>活动状态</th><th>创建者</th><th style="text-align:center;">管理</th>
            </tr>
            </thead>
            
            <tbody id="user_list">
            </tbody>
          </table>
        </div>
      </div>
    </div>

    <footer class="admin-content-footer">
    </footer>
  </div>
  <!-- content end -->

</div>

<a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>

<script src="../../../assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="../../../assets/js/amazeui.min.js"></script>
<script src="../../../assets/js/app.js"></script>
<script src="../../../js/exit_and_showname.js"></script>
<script src="../../../js/parse_long_to_date.js"></script>
</body>
</html>
